package demo3;

//静态内部类
class OutClass1 {

    private int data1 = 10;
    public int data2 = 20;
    public static int data3 = 30;

    //静态内部类
    static class InnerClass {
        private int data4 = 40;
        public int data5 = 50;
        static int data6 = 60;

        public void innerclasstest() {
            System.out.println("innerclass");
            OutClass1 outclass1 = new OutClass1();

            System.out.println(outclass1.data1);//静态内部类是不依赖对象的，所以要拿到外部类非静态类变量，需要实例化外部类对象才能拿到
            System.out.println(outclass1.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }

    }   

    public void outclasstest() {
        System.out.println("outclasstest");
    }
}


//实例内部类
class OutClass2 {
    public int data1 = 10;
    private int data2 = 20;
    public static int data3 = 30;

    //实例内部类
    class InnerClass {
        public int data4 = 40;
        private int data5 = 50;
        public static int data6 = 60;

        public void innerclasstest() {
            System.out.println(data1);
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }

    }
}


public class Test {

    //静态内部类
    public static void main1(String[] args) {
        OutClass1.InnerClass innerclass = new OutClass1.InnerClass();//实例化内部类对象
        innerclass.innerclasstest();

    }

    //实例内部类
    public static void main(String[] args) {
        OutClass2 outclass2 = new OutClass2();//先实例化外部类
        OutClass2.InnerClass innerclass = outclass2.new InnerClass();//通过外部类对象实例化内部类
        innerclass.innerclasstest();
    }

}
